package com.deer.wms.base.system.web.zhBusiness.business;

import com.deer.wms.base.system.model.bill.MaterialDetailCriteria;
import com.deer.wms.base.system.model.bill.MaterialDetailDto;
import com.deer.wms.base.system.model.record.OperationRecord;
import com.deer.wms.base.system.model.zh.IngotIocus;
import com.deer.wms.base.system.service.bill.IMaterialDetailService;
import com.deer.wms.base.system.service.record.OperationRecordService;
import com.deer.wms.base.system.service.zh.IngotIocusService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Condition;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 晶棒履历
 * @author 李帅辰
 * @date 2021/5/27 14:52
 */
@Controller
@RequestMapping("/IngotIocus")
public class IngotIocusController extends BaseController {

    @Autowired
    private IngotIocusService ingotIocusService;

    @Autowired
    private IMaterialDetailService materialDetailService;
    @Autowired
    private OperationRecordService operationRecordService;


    private String prefix = "ingotIocus";

    /**
     *跳转显示页面
     * @return
     */
    @RequiresPermissions("ingotIocus:view")
    @GetMapping
    public String ShelfPlan()
    {
        return prefix + "/ingotIocus";
    }

    @RequiresPermissions("ingotIocus:findList")
    @PostMapping("/findList")
    @ResponseBody
    public TableDataInfo findList(IngotIocus ingotIocus) {
        startPage();
        List<IngotIocus> list = ingotIocusService.findIngotIocusList(ingotIocus);
        return getDataTable(list);
    }

    @ResponseBody
    @PostMapping("/findMap")
    public Map<String,Object> mainMap(String materialId) {
        Map<String,Object> mapMain= new HashMap<>();
        MaterialDetailCriteria materialDetailCriteria = new MaterialDetailCriteria();
        materialDetailCriteria.setMaterialId(materialId);
        List<MaterialDetailDto> materialDetailDtos = materialDetailService.selectMaterialList(materialDetailCriteria);

        mapMain.put("info",materialDetailDtos);

        IngotIocus ingotIocus = new IngotIocus();
        ingotIocus.setType(1);
        ingotIocus.setMaterialId(materialId);
        List<IngotIocus> list = ingotIocusService.findIngotIocusList(ingotIocus);
        mapMain.put("billIn",list);

        ingotIocus.setType(2);
        List<IngotIocus> list2 = ingotIocusService.findIngotIocusList(ingotIocus);
        mapMain.put("billOut",list2);

        ingotIocus.setType(3);
        List<IngotIocus> list3 = ingotIocusService.findIngotIocusList(ingotIocus);
        mapMain.put("boxItem",list3);

        Condition condition=new Condition(OperationRecord.class);
        condition.createCriteria().andCondition("materialid",materialId);
        List<OperationRecord> byCondition = operationRecordService.findByCondition(condition);
        mapMain.put("operationRecord",byCondition);

        return mapMain;
    }


}
